

#include "pf_math.h"

void UI_DlgRotate::init() {
    PF_SETTINGS->beginGroup("/Modify");
    copies = PF_SETTINGS->readEntry("/RotateCopies", "10");
    numberMode = PF_SETTINGS->readNumEntry("/RotateMode", 0);
    angle = PF_SETTINGS->readEntry("/RotateAngle", "90.0");
    useCurrentLayer =
        (bool)PF_SETTINGS->readNumEntry("/RotateUseCurrentLayer", 0);
    useCurrentAttributes =
        (bool)PF_SETTINGS->readNumEntry("/RotateUseCurrentAttributes", 0);
    PF_SETTINGS->endGroup();

    switch (numberMode) {
    case 0:
        rbMove->setChecked(true);
        break;
    case 1:
        rbCopy->setChecked(true);
        break;
    case 2:
        rbMultiCopy->setChecked(true);
        break;
    default:
        break;
    }
    leNumber->setText(copies);
    leAngle->setText(angle);
    cbCurrentAttributes->setChecked(useCurrentAttributes);
    cbCurrentLayer->setChecked(useCurrentLayer);
}

void UI_DlgRotate::destroy() {
    PF_SETTINGS->beginGroup("/Modify");
    PF_SETTINGS->writeEntry("/RotateCopies", leNumber->text());
    if (rbMove->isChecked()) {
        numberMode = 0;
    } else if (rbCopy->isChecked()) {
        numberMode = 1;
    } else {
        numberMode = 2;
    }
    PF_SETTINGS->writeEntry("/RotateMode", numberMode);
    PF_SETTINGS->writeEntry("/RotateAngle", leAngle->text());
    PF_SETTINGS->writeEntry("/RotateUseCurrentLayer",
                            (int)cbCurrentLayer->isChecked());
    PF_SETTINGS->writeEntry("/RotateUseCurrentAttributes",
                            (int)cbCurrentAttributes->isChecked());
    PF_SETTINGS->endGroup();
}

void UI_DlgRotate::setData(PF_RotateAttribute* d) {
    data = d;
}

void UI_DlgRotate::updateData() {
    if (rbMove->isChecked()) {
        data->number = 0;
    } else if (rbCopy->isChecked()) {
        data->number = 1;
    } else {
        data->number = leNumber->text().toInt();
    }
    data->angle = PF_Math::deg2rad(PF_Math::eval(leAngle->text()));
    data->useCurrentAttributes = cbCurrentAttributes->isChecked();
    data->useCurrentLayer = cbCurrentLayer->isChecked();
}

